/**
 * @Package: 	com.group.C3P0Utils 
 * @author: 	Liu  
 * @date: 		Dec 26, 2018 11:48:38 AM 
 */
package com.group.C3P0Utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * @ClassName:	 C3P0Utils.java
 * @Description: 数据库工具类
 * @author:		 Liu
 * @date: 		 Dec 27, 2018 9:26:32 AM 
 */
public class C3P0Utils {
	private static DataSource ds = new ComboPooledDataSource("mysql");
    /**
     * @Function: 	 C3P0Utils.java
     * @Description: 获取连接
     * @param:		   参数
     * @return:		   返回conn
     * @author: 	 Liu
     * @date:		 Dec 27, 2018 9:24:31 AM 
     */
    public static Connection getConnection() throws SQLException {
          return ds.getConnection();
    }
    /**
     * @Function: 	 C3P0Utils.java
     * @Description: 获取数据源
     * @param:		   参数
     * @return:		 DataSource
     * @author: 	 Liu
     * @date:		 Dec 27, 2018 9:25:25 AM 
     */
    public static DataSource getDataSource() {
          return ds;
    }
	
	/**
	 * @Function: 	 C3P0Utils.java
	 * @Description: 关闭资源
	 * @param:		   参数
	 * @return:		 
	 * @author: 	 Liu
	 * @date:		 Dec 27, 2018 9:25:36 AM 
	 */
	public static void close(ResultSet rs,Statement stmt,Connection conn) {
		if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (stmt != null) {
            try {
            	stmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
	}
}
